package com.lxk;



import java.util.*;

/**
 * @author 柳新宽
 * @create 2022-03-31  15:00
 * @describe
 */
public class FimMain {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        FilmManager fm = new FilmManager();
        fm.init();//初始化
        while(true){
            System.out.println("-----------功能-----------");
            System.out.println("1.展示旗下影院的信息");
            System.out.println("2.展示旗下影院放映的影片信息");//两个影院在播放同一个电影
            System.out.println("3.根据影院的名称查看旗下放映的影片");
            System.out.println("4.新增一个影片，添加在对应的影院");
            System.out.println("5.下架一个影片(可选择所有下架和针对性下载)");
            System.out.println("6.根据题材查询影片");
            System.out.println("7.根据主演查询影片");
            System.out.println("请输入选择");
            int key = sc.nextInt();
            switch (key){
                case 1 :
                    fm.showAllCinema();
                    break;
                case 2 :
                    HashSet<Film> set = fm.showAllFilm();
                    for (Film film : set) {
                        System.out.println(film);
                    }
                    break;
                case 3 :
                    List<String> cinemaNames = fm.findAllCinemaName();
                    System.out.println("所有的影院如下：");
                    for (String cinemaName : cinemaNames) {
                        System.out.println(cinemaName);
                    }
                    System.out.println("请选择影院");
                    String selectCinemaName = sc.next();
                    fm.showFilmByCinema(selectCinemaName);
                    break;
                case 4 :
                    System.out.println("请输入影片的名称");
                    String addFilmName = sc.next(); //新增的影片名称
                    boolean addFlag = fm.existsFilm(addFilmName);
                    if(addFlag){
                        //输入影片其他信息
                        System.out.println("请输入电影的类型");
                        String addFilmType = sc.next();
                        System.out.println("请输入电影的时长");
                        String addFilmTime = sc.next();
                        System.out.println("请输入电影的主演");
                        String addFilmActor = sc.next();
                        System.out.println("请输入电影的简介");
                        String addFilmIntro = sc.next();
                        Film addFilm = new Film(null, addFilmName, addFilmType, addFilmTime, addFilmActor, addFilmIntro, new Date());
                        //拿到所有的影院 让用户选择
                        List<String> addCinemaNames = fm.findAllCinemaName();
                        for (String addCinemaName : addCinemaNames) {
                            System.out.println(addCinemaName);
                        }
                        System.out.println("请选择上映的影院");
                        String publicationCinemaNames = sc.next(); //上映的影院
                        fm.addFilmAndPublication(addFilm,publicationCinemaNames);
                    }else{
                        System.out.println("此影片已存在");
                    }
                    break;
                case 5 :
                    //下架一个影片
                    HashSet<Film> set2 = fm.showAllFilm();
                    for (Film film : set2) {
                        System.out.println(film.getFilmName());
                    }
                    System.out.println("请选择下架的影片");
                    String deleteFilmName = sc.next();
                    //根据待删除的电影名 获取正在哪些影院放映
                    List<String> list = fm.getCinemaByFilmName(deleteFilmName);
                    for (String s : list) {
                        System.out.println(s);
                    }
                    System.out.println("请输入要下架"+deleteFilmName+"的影院:");
                    String deleteFilmForCinemaName = sc.next();
                    //调用方法完成下架
                    fm.deleteFilmByCinema(deleteFilmName,deleteFilmForCinemaName);
                    break;
                case 6 :
                    //根据题材查询影片
                    //查询正在上映的电影有哪些题材
                    Set<String> filmTypes = fm.getAllType();
                    for (String filmType : filmTypes) {
                        System.out.println(filmType);
                    }
                    System.out.println("请输入查询的电影题材");
                    String findType = sc.next();
                    List<Film> list1 = fm.getFilmByType(findType);
                    for (Film film : list1) {
                        System.out.println(film);
                    }
                    break;
            }

        }
    }
}
